﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Printing;

namespace BaMusaSoft.RPS.RPSServices
{
    public class PrinterBounds
    {
        [DllImport("gdi32.dll")]
        private static extern Int32
            GetDeviceCaps(IntPtr hdc, Int32 capindex);

        private const int PHYSICALOFFSETX = 112;
        private const int PHYSICALOFFSETY = 113;

        //public Rectangle Bounds { get; private set; }
        public float OffsetX { get; private set; }
        public float OffsetY { get; private set; }

        public PrinterBounds(Graphics g)
        {
            IntPtr hDC = g.GetHdc();

            OffsetX = GetDeviceCaps(hDC, PHYSICALOFFSETX);
            OffsetY = GetDeviceCaps(hDC, PHYSICALOFFSETY);

            g.ReleaseHdc(hDC);

            OffsetX = (int)(OffsetX * 100.0 / g.DpiX);
            OffsetY = (int)(OffsetY * 100.0 / g.DpiY);

            //Bounds = e.MarginBounds;

            //Bounds.Offset(-OffsetX, -OffsetY);
        }
    }
}
